package cn.yunhe.model;

import cn.yunhe.util.MapUtil;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;

/**
 * ⼀个地图有多个图层，层层之间遮盖
 */
public class Map extends JFrame {
    //层⾼，有⼏张图层，游戏难度相关
    private int floorHeight;
    private List<Layer> list = new ArrayList<>();

    public int getFloorHeight() {
        return floorHeight;
    }

    public void setFloorHeight(int floorHeight) {
        this.floorHeight = floorHeight;
    }

    public List<Layer> getList() {
        return list;
    }

    public void setList(List<Layer> list) {
        this.list = list;
    }

    /**
     * 判断当前map中所有牌，是否置灰
     */
    public void compareAll() {
        //i=0,最顶层Layer不需要判断
        for (int i = 1; i < list.size(); i++) {
            Layer layer = list.get(i);
            Cell[][] cells = layer.getCells();
            for (int row = 0; row < cells.length; row++) {
                for (int col = 0; col < cells[row].length; col++) {
                    Cell cell = cells[row][col];
                    if (cell.getState() == 1) { //有牌
                        Brand brand = cell.getBrand();
                        //注意是给上⼀层，i=1，layer.getParent就是上⼀层 i=0
                        boolean result = MapUtil.compare(brand, layer.getParent());
                        brand.setGray(result);//设置为灰⾊
                    }
                }
            }
        }
    }
}